<?php
    $this->stylesheet()->controller();
?>
<form action=""
    name="<?php echo $this->form->getName(); ?>"
    id="<?php echo $this->form->getId(); ?>"
    enctype="<?php echo $this->form->getEnctype(); ?>"
    method="<?php echo $this->form->getMethod();?>">

<ul class="form-list">
    <li>
        <div class="form-title">
            <label for="label"><?php echo $this->form->label->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->label); ?>
        <div class="errors"><?php
                foreach ($this->form->getMessages('label') as $message){
                    echo "<p>" . $this->escape($message) . "</p>";
                }?>
            </div>
        </div>
    </li>
    <li>
        <div class="form-title">
            <label for="parent"><?php echo $this->form->parent->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->parent); ?></div>
    </li>
    <li>
        <div class="form-title">
            <label for="title"><?php echo $this->form->title->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->title); ?></div>

    </li>

    <li>
        <div class="form-title">
            <label for="class"><?php echo $this->form->class->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->class); ?></div>
        <hr />
    </li>

    <li>
        <div class="form-title">
            <label for="visible"><?php echo $this->form->visible->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->visible); ?></div>
    </li>
    <li>
        <div class="form-title">
            <label for="active"><?php echo $this->form->active->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->active); ?></div>
    </li>

    <li>
        <div class="form-title">
            <label for="target"><?php echo $this->form->target->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->target); ?></div>
        <hr />
    </li>

    <li>
        <div class="form-title">
            <label for="linkType"><?php echo $this->form->linkType->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->linkType); ?></div>
    </li>

    <li class="type-route">
        <div class="form-title">
            <label for="route"><?php echo $this->form->route->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->route); ?></div>
    </li>

    <li class="routes">
    <?php
    if ($this->routes):
        foreach ($this->routes as $route):
            if ($route['name']):?>
                <div style="display:none;" id="route-<?php echo $route['name']; ?>">
                <p><label>Route type:</label> <?php echo $route['type']; ?></p>
                <?php if ($_SERVER && isset($_SERVER["HTTP_HOST"])) {
                    $host = $_SERVER["HTTP_HOST"];
                } else {
                    $host = 'localhost';
                }?>
                <p><label>Example path:</label> <i>http://<?php echo $host.$route['path']; ?></i></p>
                <?php
                if ($route['type'] == Menu_Model_Menu::ROUTE_TYPE_ROUTE):
                    foreach ($route['params'] as $key => $param):
                ?>
                <label><?php echo $param; ?></label>
                <div>
                    <input id="<?php echo $route['name'] . '-' . $param; ?>"  type="text" name="params[<?php echo $param; ?>]" value="<?php echo $param; ?>">
                </div>
                <br />
                    <?php
                    endforeach;?>
                    <?php
                    if ($route['wildcard'] === true):?>
                    <p class="new-parameters"></p>
                        <span class="ui-state-default ui-corner-all">Custom parameter name:</span>
                        <div>
                            <input class="newparam" type="text" name="newparam" value="">
                            <input class="aForm-field-valid ui-button ui-widget ui-state-default ui-corner-all" onclick="addParam();" alt="Add parameter" type="button" name="add" value="+">
                        </div>


                    <?php
                    endif;
                endif;
                if ($route['type'] == Menu_Model_Menu::ROUTE_TYPE_REGEX):
                    foreach ($route['params'] as $key => $param):?>
                        <label>Param[<?php echo $key; ?>]</label>
                        <div>
                            <input id="<?php echo $route['name'] . '-' . $param; ?>" type="text" name="params[<?php echo $param; ?>]" value="<?php echo $param; ?>">
                        </div>
                        <br />
                            <?php
                    endforeach;
                endif;
                if ($route['type'] == Menu_Model_Menu::ROUTE_TYPE_MODULE):?>
                        <label>Module</label>
                        <div>
                        <select onChange="changeModule();" name="params[module]" id="mvcModule" >
                            <option value="" label="---">---</option>
                            <?php
                            foreach ($route['modules'] as $key => $param):?>
                                <option value="<?php echo $key; ?>" label="<?php echo $key; ?>"><?php echo $key; ?></option>
                            <?php
                            endforeach;
                        ?>
                        </select>
                        </div>
                        <div class="modules">

                            <?php
                            foreach ($route['modules'] as $modul => $controllers):?>
                                <div style="display:none;" id="module-<?php echo $modul; ?>">
                                    <label>Controller</label>
                                    <div>
                                        <select onChange="getActions('<?php echo $modul; ?>')" name="params[controller]" class="controller" id="<?php echo $modul; ?>-Controller" >
                                            <option value="" label="---">---</option>
                                            <?php
                                            foreach ($controllers as $key => $param):?>
                                                <option value="<?php echo $key; ?>" label="<?php echo $key; ?>"><?php echo $key; ?></option>
                                            <?php
                                            endforeach;
                                            ?>
                                        </select>
                                    </div>
                                </div>

                                <?php
                                foreach ($controllers as $key => $param):?>
                                <div style="display:none;" id="<?php echo $modul.'-'.$key.'-'; ?>actions">
                                    <label>Action</label>
                                    <div style="display:none;" id="<?php echo $modul.'-'.$key.'-'; ?>action"></div>
                                </div>
                                <?php
                                endforeach;
                                ?>
                            <?php
                            endforeach;
                            ?>
                        </div>

                        <p class="new-parameters"></p>
                        <span class="ui-state-default ui-corner-all">Custom parameter name:</span>
                        <div>
                            <input class="newparam" type="text" name="newparam" value="">
                            <input class="aForm-field-valid ui-button ui-widget ui-state-default ui-corner-all" onclick="addParam();" alt="Add parameter" type="button" name="add" value="+">
                        </div>

                    <?php
                endif;
            endif;?>
            </div>
             <?php
        endforeach;
    endif;
    ?>
    </li>
    <li class="type-uri">
        <div class="form-title">
            <label for="uri"><?php echo $this->form->uri->getLabel();?></label>
        </div>
        <div class="form-field"><?php echo $this->aElement($this->form->uri); ?></div>
        <div class="errors"><?php
                foreach ($this->form->getMessages('uri') as $message){
                    echo "<p>" . $this->escape($message) . "</p>";
                }?>
            </div>
    </li>
    <li>
        <div class="form-title"></div>
        <div class="form-field"><?php echo $this->aElement($this->form->submit); ?></div>
    </li>
</ul>
</form>
<script>
$(document).ready(function(){
    changedLinkType();
});
</script>